#include "GlobalClock.hpp"
#include "Logger.hpp"

GlobalClock::GlobalClock ():
m_countFrames(0),
m_currentDT(0.f),
m_timeElapsed(0.f),
m_timeElapsedSinceLastSecond(0.f),
m_nbframesSinceLastSecond(0.f)
{
}

GlobalClock::~GlobalClock ()
{
	// print average fps
	LogInfo << "Average FPS : " << float(m_countFrames)/m_timeElapsed << LogEnd;
}

GlobalClock& GlobalClock::instance()
{
	static GlobalClock gc;
	return gc;
}

void GlobalClock::update(const float dt)
{
	++m_countFrames;
	++m_nbframesSinceLastSecond;
	m_currentDT = dt;
	
	m_timeElapsed += dt;
	
	// print fps
	if(m_timeElapsed - m_timeElapsedSinceLastSecond >= 1.f)
	{
		LogInfo << "fps :" << int(m_nbframesSinceLastSecond) << LogEnd;
		m_nbframesSinceLastSecond = 0;
		m_timeElapsedSinceLastSecond = m_timeElapsed;
	}
}

float GlobalClock :: deltaTime() const
{
	return m_currentDT;
}		

